package com.hrg.demo.job;

import com.hrg.demo.config.FileCleanupProperties;
import com.hrg.demo.service.FileCleanupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author shenzq
 */
@Slf4j
@Configuration
@EnableScheduling
public class FileCleanupScheduler {

    @Autowired
    private FileCleanupService fileCleanupService;

    @Autowired
    private FileCleanupProperties cleanupProperties;

    /**
     * 定时清理任务
     */
    @Scheduled(cron = "${images.param.cleanup.cron}")
    public void scheduledCleanup() {
        log.info("定时文件清理任务开始执行...");
        fileCleanupService.cleanupFiles();
        log.info("定时文件清理任务执行完成");
    }

    /**
     * 每天凌晨1点统计目录信息（可选）
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void dailyStats() {
        log.info("生成每日目录统计报告...");
        fileCleanupService.printDirectoryStats();
    }
}
